<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
String contextPath = request.getContextPath();
String groupId = request.getParameter("tabId_");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>字典值管理</title>
<jsp:include page="/inc/inc.jsp" />
<script type="text/javascript">
var contextPath = '<%=contextPath%>';
var action = 'dictionaryAction';
var vo=[];
$(function(){
	loadTree();	
	<%=(String)request.getAttribute("js")%>
}); 

function add(){
	showWin('新增',contextPath+'/jframe/cfg/edit/dicdataEdit.jsp?id=0',300,200);
}

function edit(){
	var rows = $('#grid').datagrid('getSelections');
	if(rows.length>1){
		alertWarn("请您只选择一条记录进行操作！");
		return;
	}else if(rows.length==0){
		alertError("请您选择要操作的记录！");
		return;
	}
	var id = getSelection();
	showWin('编辑',contextPath+'/jframe/cfg/edit/dicdataEdit.jsp?&id='+id,300,200);
}
 
function del(){
	var ids = getSelections();
	if(ids==""){
		alertError("请您选择要操作的记录！");
		return;
	}else{
		econfirm('警告','确定要删除所选择的数据？',function(r){
    		if(r){
    			var url = action+".do?method=delete";
    			$.ajax({
    				url:url,
    		 		type: 'post',
    			    data:{
    			    	ids:ids
    			    },
    			    dataType: 'json',
    			    error: function(){
    			        alertError('删除失败!');
    			    },
    			    success: function(data){
    			    	alertInfo('成功删除所选记录！');
    			    	$('#grid').datagrid('reload');
    			    }
    			});
    		}
    	});
		$('#grid').datagrid('clearSelections');
	}	
}

function find(){
	vo=[];
	var name = $('#value').val();
	if(name!=null&&name!="")
		vo.push({name:'value',type:'String',logic:'and',operators:'like',value:name});
    $('#grid').datagrid('load',{
        conditions: obj2json(vo)
   });
}

function loadTree(){
	  var setting = {	            
	            data: {
	                    simpleData: {
	                    	   enable: true,
	                            idKey: "id",
	                            pIdKey: "pId",
	                            rootPId: 0
	                    }
	            },
	            async: { 
	                    type: "post",
	                    enable: true,
	                    url: 'dictionaryAction.do?method=getRightTrees',
	                    otherParam: {}
	            },
	            callback : {
	                onClick: function(event,treeId,node){
	                	vo=[];
	    				vo.push({name:'typeId',type:'int',logic:'and',operators:'=',value:node.id});	
	    				$('#grid').datagrid('load',{
	    				       conditions: obj2json(vo)
	    				});
	                }
	            },
	    };
	    $.fn.zTree.init($("#mtree"), setting);//初始化树对象a
}
</script>
</head>
<body class="easyui-layout"> 
	 <div region="west" border="true" title="子系统" class="cs-west" style="width:180px;height: 100%" border="false">
		<ul id="mtree"  class='ztree'></ul>
	</div>
	<div  region="center" border="true" border="false" style="height:100%">
		<div id="tb">
		      <a class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">新增</a>
			 <a class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">编辑</a>
			 <a class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del()">删除</a>
			 <span>字典值：</span><input id="value" name="value" type="text" style="width: 100px;">
			 <a class="easyui-linkbutton" plain="true" onclick="find()" iconCls="icon-search">查询</a>
		</div>
		<table id="grid" toolbar="#tb" border="0"></table>
	</div>
</body>
</html>